﻿using System;
using System.Collections.Generic;
using Dost.Khcn.Data.EntityModel;
using Dost.Khcn.Data.Implements;
using Dost.Khcn.Data.Interfaces;

namespace Dost.Khcn.Biz
{
    public class HinhThucDaoTaoBiz
    {
        #region Properties

        private IHinhThucDaoTaoDao _hinhThucDaoTaoDao;
        private IHinhThucDaoTaoDao HinhThucDaoTaoData
        {
            get { return _hinhThucDaoTaoDao ?? (_hinhThucDaoTaoDao = new HinhThucDaoTaoDao()); }
        }

        #endregion

        #region Constructors

        #endregion

        #region Methods

        public List<HinhThucDaoTao> GetAllHinhThucDaoTaos()
        {
            return HinhThucDaoTaoData.GetAll();
        }

        public object GetHinhThucDaoTaos(int startIndex, int pageSize, string sorting, string name)
        {
            try
            {
                int totalRecords;
                var hinhThucDaoTaos = HinhThucDaoTaoData.GetHinhThucDaoTaos(startIndex, pageSize, sorting, name, out totalRecords);
                return new { Result = "OK", Records = hinhThucDaoTaos, TotalRecordCount = totalRecords };
            }
            catch (Exception ex)
            {
                return new { Result = "ERROR", ex.Message };
            }
        }

        public HinhThucDaoTao CreateHinhThucDaoTao(HinhThucDaoTao hinhThucDaoTao)
        {
            // validate inputs
            if (hinhThucDaoTao == null) return null;

            return string.IsNullOrEmpty(hinhThucDaoTao.Ten) ? null : HinhThucDaoTaoData.AddHinhThucDaoTao(hinhThucDaoTao);
        }

        public HinhThucDaoTao GetById(int id)
        {
            return id > 0 ? HinhThucDaoTaoData.GetById(id) : null;
        }

        public void UpdateHinhThucDaoTao(HinhThucDaoTao hinhThucDaoTao)
        {
            if (hinhThucDaoTao == null) return;

            HinhThucDaoTaoData.UpdateHinhThucDaoTao(hinhThucDaoTao);
        }

        public object DeleteHinhThucDaoTao(int id)
        {
            try
            {
                HinhThucDaoTaoData.DeleteHinhThucDaoTao(id);
                return new { Result = "OK" };
            }
            catch (Exception ex)
            {
                return new { Result = "ERROR", ex.Message };
            }
        }

        #endregion
    }
}
